package com.ruoyi.BasicSettings.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.BasicSettings.domain.DrugManagement;
import com.ruoyi.BasicSettings.service.IDrugManagementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药品管理Controller
 * 
 * @author ruoyi
 * @date 2025-08-23
 */
@RestController
@RequestMapping("/BasicSettings/management")
public class DrugManagementController extends BaseController
{
    @Autowired
    private IDrugManagementService drugManagementService;

    /**
     * 查询药品管理列表
     */
    @PreAuthorize("@ss.hasPermi('BasicSettings:management:list')")
    @GetMapping("/list")
    public TableDataInfo list(DrugManagement drugManagement)
    {
        startPage();
        List<DrugManagement> list = drugManagementService.selectDrugManagementList(drugManagement);
        return getDataTable(list);
    }

    /**
     * 导出药品管理列表
     */
    @PreAuthorize("@ss.hasPermi('BasicSettings:management:export')")
    @Log(title = "药品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DrugManagement drugManagement)
    {
        List<DrugManagement> list = drugManagementService.selectDrugManagementList(drugManagement);
        ExcelUtil<DrugManagement> util = new ExcelUtil<DrugManagement>(DrugManagement.class);
        util.exportExcel(response, list, "药品管理数据");
    }

    /**
     * 获取药品管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('BasicSettings:management:query')")
    @GetMapping(value = "/{managementId}")
    public AjaxResult getInfo(@PathVariable("managementId") Long managementId)
    {
        return success(drugManagementService.selectDrugManagementByManagementId(managementId));
    }

    /**
     * 新增药品管理
     */
    @PreAuthorize("@ss.hasPermi('BasicSettings:management:add')")
    @Log(title = "药品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DrugManagement drugManagement)
    {
        return toAjax(drugManagementService.insertDrugManagement(drugManagement));
    }

    /**
     * 修改药品管理
     */
    @PreAuthorize("@ss.hasPermi('BasicSettings:management:edit')")
    @Log(title = "药品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrugManagement drugManagement)
    {
        return toAjax(drugManagementService.updateDrugManagement(drugManagement));
    }

    /**
     * 删除药品管理
     */
    @PreAuthorize("@ss.hasPermi('BasicSettings:management:remove')")
    @Log(title = "药品管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{managementIds}")
    public AjaxResult remove(@PathVariable Long[] managementIds)
    {
        return toAjax(drugManagementService.deleteDrugManagementByManagementIds(managementIds));
    }
}
